package com.tmzn.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class SplitDataUtil {

    @Autowired
    private Environment env;

    private static Environment environment;

    @PostConstruct
    public void init(){
        environment = this.env;
    }
    public static void main(String[] args) {
        System.out.println(getSplitTableNum("864606060148920"));
    }
    public static int getSplitTableNum(String imei){
        //分表仅在线上环境
        String activeProfile = environment.getProperty("spring.profiles.active");
        if(!activeProfile.equals("prod")) {
            return 0;
        }

        int len = imei.length();
        String substring = imei.substring(len - 2);
        int table = 100;
        try{
            table = Integer.parseInt(substring);
        }catch (Exception e){

        }
        return table;
    }

    private static  int hash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }
}
